import re

xfile = open('x_try_re.html', 'r')
xtext = xfile.read()
xfile.close()

xregexp = re.compile(r'<head>(.*<title>(.*)</title>).*</head>', re.IGNORECASE | re.DOTALL)
xmatch = xregexp.search(xtext)
if xmatch is not None:
    print(f'match: {xmatch.group()}, sub-groups: {xmatch.groups()}')
else:
    print('Not match.')

xregexp = re.compile(r'(<h(\d)>(.*?)</h\2>)', re.IGNORECASE | re.DOTALL)
xmatch = xregexp.findall(xtext)
if xmatch is not None:
    for x in xmatch:
        print(x)
else:
    print('Not match.')
